package com.naml.d_methods;

/**
 * @author marin
 * @version 1.0
 * @date 2025/4/28 20:48
 * @desc 演示线程插队---被插队的线程需要等待插队的线程全部走完。
 */
@SuppressWarnings("all")
public class ThreadJoin03 {
    public static void main(String[] args) throws InterruptedException {
        ThreadJoin threadJoin = new ThreadJoin();
        threadJoin.setName("小张");
        threadJoin.start();

        for (int i = 1; i <= 15; i++) {
            System.out.println(Thread.currentThread().getName() + ":排队" + i +"分钟...");
            Thread.sleep(1000);
            if (i == 10) {
                System.out.println(Thread.currentThread().getName() + ":准备让"+threadJoin.getName()+"先排队...");
                threadJoin.join();
            }
        }
    }
}

class ThreadJoin extends Thread {

    @Override
    public void run() {
        for (int i = 1; i <= 30; i++) {
            try {
                System.err.println(Thread.currentThread().getName() + ":排队" + i +"分钟...");
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}